package com.ruoyi.map.controller;

import com.ruoyi.map.service.MapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.HashMap;

/**
 * 地图管理Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/map")
public class MapController
{
    @Autowired
    private MapService mapService;

    /**
     * 获取地图配置信息
     */
    @GetMapping("/config")
    public Map<String, Object> getMapConfig()
    {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "操作成功");
        result.put("data", mapService.getMapConfig());
        return result;
    }

    /**
     * 地理编码（地址转坐标）
     */
    @GetMapping("/geocode")
    public Map<String, Object> geocode(@RequestParam String address)
    {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "操作成功");
        result.put("data", mapService.geocode(address));
        return result;
    }

    /**
     * 逆地理编码（坐标转地址）
     */
    @GetMapping("/regeocode")
    public Map<String, Object> regeocode(@RequestParam String location)
    {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "操作成功");
        result.put("data", mapService.regeocode(location));
        return result;
    }

    /**
     * 搜索周边POI
     */
    @GetMapping("/search-poi")
    public Map<String, Object> searchPoi(
            @RequestParam String keywords,
            @RequestParam(required = false) String location,
            @RequestParam(defaultValue = "5000") Integer radius)
    {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "操作成功");
        result.put("data", mapService.searchPoi(keywords, location, radius));
        return result;
    }

    /**
     * 全国范围搜索POI
     */
    @GetMapping("/search-poi-nationwide")
    public Map<String, Object> searchPoiNationwide(
            @RequestParam String keywords,
            @RequestParam(required = false) String city)
    {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "操作成功");
        result.put("data", mapService.searchPoiNationwide(keywords, city));
        return result;
    }
}
